<?php
    /**
    * Update logs
    * June 4, 2011 - trungdt - Add tag search
*/

    if (!defined("EXPONENT")) exit("");
    $id ="";
    $rsnews=null;
    if (isset($_GET['id']))
    {
        $id=$_GET['id'];
        if (!is_int($id))
        {
            $id=_ab_safe_html_string($id);
            $rsnews = $db->selectObject("rsnewsitem","internal_name = '{$id}'");
        }
        else{
            $rsnews = $db->selectObject("rsnewsitem","id= {$id}");
        }
    }
    
    
    if ($rsnews != null) {
        exponent_flow_set(SYS_FLOW_PUBLIC,SYS_FLOW_ACTION);
        $loc = unserialize($rsnews->location_data);
        $iloc = $loc;
        $iloc->int = $rsnews->id;

        $rsnews->permissions = array(
        "edit_item"=>((exponent_permissions_check("edit_item",$loc) || exponent_permissions_check("edit_item",$iloc)) ? 1 : 0),
        "delete_item"=>((exponent_permissions_check("delete_item",$loc) || exponent_permissions_check("delete_item",$iloc)) ? 1 : 0),
        "administrate"=>((exponent_permissions_check("administrate",$loc) || exponent_permissions_check("administrate",$iloc)) ? 1 : 0)
        );
        $file = $db->selectObject("file","id=".$rsnews->file_id);
        if(!empty($file)){
            $rsnews->image = BASE_URL . "/".$file->directory.'/'.$file->filename;
        }
        $rsnews->real_posted = ($rsnews->publish != 0 ? $rsnews->publish : $rsnews->posted);
        
        // date time
        $date_time=0;
        if ($rsnews->edited == 0)
            $date_time=$rsnews->posted;
        else
            $date_time=$rsnews->edited;

        $rsnews->datetime=_ab_dateFormat($date_time);
        // end of date time
        
        // tags split
        $temp=explode(",",$rsnews->tags);
        foreach ($temp as $k=>$v){
            $v=trim($v);
            if ($v == "")
                unset($temp[$k]);
            else
                $temp[$k]=$v; 
        }
        $rsnews->tags_array=$temp;
        // tag end
        
        
        // for poster name
        $temp=$db->selectObject("user","id = " . $rsnews->poster);
        $rsnews->poster_name = "";
        if ($temp)
        {
            $rsnews->poster_name = $temp-> firstname . $temp->lastname;
        }
        
        // June 6, 2011 - trungdt - add other news (relative news)
        $other_news = $db->selectObjects("rsnewsitem", " (approved =1) AND (location_data='{$rsnews->location_data}') AND (posted < {$rsnews->posted}) ORDER BY edited DESC, posted DESC");
        foreach ($other_news as $k=>$v){
            $v->post_date=_ab_dateFormat($v->posted,true);
        }
        // June 6, 2011 - trungdt - add other news (relative news) - end
        
        $view = (isset($_GET['view']) ? $_GET['view'] : "_viewSingle");
        $template = new template("rsnewsmodule",$view,$loc);

        $template->assign("newsitem",$rsnews);
        $template->assign("other_news",$other_news);
        $template->assign("loc",$loc);
        // register page title
        _ab_theme_action_register_title($rsnews->title." - ".exponent_lang_getText("rsnews_view_page_title")." - ".SITE_TITLE);
        $template->output();
    } else {
        echo SITE_404_HTML;
    }

?>
